package com.hsp.demo_07_money;

import com.sun.org.apache.bcel.internal.generic.NEW;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class MoneyCharge {
    public static void main(String[] args) {
        /*
         需求：做一个类似微信钱包的零钱通小程序
         1、先显示页面
            由于是显示菜单，所以使用do-while循环，因为菜单至少要显示一次
         */

        boolean flag = true;
        Scanner scanner = new Scanner(System.in);
        String result = "";
        String details = "---------------零钱通明细------------ \n";
        /*details += "收入&支出" + "\t" + "本次消费金额" + "\t" + "消费时间" + "\t"
                + "余额" + "\n";*/
        //本次金额
        double money= 0.0;
        //余额
        double balance = 0.0;
        //用来格式化时间
        SimpleDateFormat format = new SimpleDateFormat("YYYY-MM-dd HH:mm");

        do{
            System.out.println("\n==============零钱通菜单=============");
            System.out.println("\t\t\t 1、零钱通明细");
            System.out.println("\t\t\t 2、收益入账");
            System.out.println("\t\t\t 3、消费");
            System.out.println("\t\t\t 4、退出");

            System.out.print("请选择(1-4)：");
            result = scanner.next();

            //在jdk1.7之后，switch支持了String
            switch(result){
                case "1":
                    System.out.print(details);
                    break;
                case "2":
                    System.out.print("收益入账金额：");
                    money = scanner.nextDouble();
                    balance += money;
                    details += "收益入账" + "\t\t" + money + "\t" + format.format(new Date()) +
                                "\t" + balance + "\n";
                    break;
                case "3":
                    System.out.println("3、消费");
                    break;
                case "4":
                    System.out.println("4、退出");
                    flag = false;
                    break;
                default:
                    System.out.println("输入有误，请重新输入!");
            }
        }while(flag);

        System.out.println("==============退出=============");


    }

}
